﻿Imports System.Data.SqlClient

Public Class clsGafetes
    Private mintidEmpleado As Integer
    Private mdatVence As Date

    Public Property idempleado() As Integer
        Get
            Return mintidEmpleado
        End Get
        Set(ByVal value As Integer)
            mintidEmpleado = value
        End Set
    End Property
    Public Property Vence() As Date
        Get
            Return mdatVence
        End Get
        Set(ByVal value As Date)
            mdatVence = value
        End Set
    End Property
    Public Sub New()
        mintidEmpleado = 0
        mdatVence = Now()
       
    End Sub
    Sub Insertar()
        Dim sql As String = "Insert Into Gafetes (" & _
                           "IdEmpleado," & _
                           "Vence)" & _
                           "VALUES (" & _
                           "@IdEmpleado," & _
                           "@Vence)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdEmpleado", mintidEmpleado)
        Command.Parameters.AddWithValue("Vence", mdatVence)


        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Sub Actualizar()
        Dim sql As String = "Update Gafetes SET " & _
                          "Vence=@Vence" & _
                          " WHERE idEmpleado=@IdEmpleado"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdEmpleado", mintidEmpleado)
        Command.Parameters.AddWithValue("Vence", mdatVence)


        cnConn.Open()
        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
